// --------------------------------------------------
// Test script for class lattice_1DTRI
// Also can be used as open loop simulation
// 
// Author: Xinyu Zhang (zxy1256@gmail.com)
// --------------------------------------------------
#include <iostream>
#include <fstream>
#include <cctype>
using namespace std;
#include "lattice_1DTRI.h"
int main(int argc, char** argv)
{
	int		i;
	double	DepRate;
	double	REPEAT;
	int		RepeatCount;
	char	flag;
	// ----------------------------------------
	// Test case 1
	/*lattice_1DTRI Lattice2(15,1,0.01,850,3,100);
	Lattice2.get();
	Lattice2.display_lattice();
	
	// Add and particles
	for(i=0;i<10;i++)
	{
		Lattice2.add_particle(1,i);
	}
	Lattice2.display_lattice();
	for(i=9;i>5;i--)
	{
		Lattice2.remove_particle(1,i);
	}
	Lattice2.display_lattice();
	
	// Reset
//	Lattice2.reset();

	// Deposition
	for(i=0;i<110;i++)
	{
		Lattice2.deposition();
	}
	//Lattice2.display_lattice();

	// Diffusion
	for(i=0;i<110;i++)
	{
		Lattice2.diffusion();
	}
	
	// Update lattice
	DepRate = 0.4;	// layer/s
	REPEAT	= 1;
	for(RepeatCount=0;RepeatCount<REPEAT;RepeatCount++)
	{
		Lattice2.reset();
		while(Lattice2.notfinish())
		{
			Lattice2.update(DepRate);
		}
	}*/
	// ----------------------------------------
	// Test case 2: compare with Gangshi's code
	if(argc!=2)
	{
		cerr << "Please speify the deposition rate\n";
		system("pause");
		exit(-1);
	}
	
	DepRate = atof(argv[1]);
	cout << "\nDepRate = " << DepRate;
	cout << "\nT_end = " << 2000/DepRate;
	cout << "\nPress C to continue or other key to quit: ";
	
	cin >> flag;
	
	if(flag != 'c'&& flag == 'C')
	{
		exit(-1);
	}
	
	cout << "\nStart";
	
	lattice_1DTRI Lattice(100,2000/DepRate,1);
	Lattice.get();
	
	REPEAT = 100;
	for(RepeatCount=0;RepeatCount<REPEAT;RepeatCount++)
	{
		cout << "\n#" << RepeatCount+1 << " of " << REPEAT << "runs";
		Lattice.reset();
		while(Lattice.notfinish())
		{
			Lattice.update(DepRate);
		}
	}
	// ----------------------------------------
	// Test 3
	
	// ----------------------------------------
	cout << "SUCCESS Testing lattice_1DTRI.h and lattice_1DTRI.cpp\n";
	cin.get();
}
